

#pragma once

#include "gamedatamanager.h"

#include "cocos2d.h"
USING_NS_CC;

static const int CAMPAIGN_EPISODE_COUNT = 3;

enum class CampaignSceneTouchPlace {
	blank,
	tab_button,
	episode_view,
	chapter_item,
	scroll_view,
};

class CampaignScene : public CCScene, public CCTargetedTouchDelegate, public CCKeypadDelegate {
public:
	CampaignScene();
	virtual ~CampaignScene();

    CREATE_FUNC(CampaignScene);

public:
	virtual bool init();
	void update(float dt);
	void handleMessage(float ticks);

	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);

private:
	void startBattle(CCObject* sender);
	void onRecharge(CCObject* sender);
	void onClose(CCObject* sender);

	void createActs();
	void switchCampaignView();
	void scrollEpisodeView(float distance);

	virtual void keyBackClicked();
	virtual void keyMenuClicked();

	virtual void onEnter();
	virtual void onExit();

private:
	CCLayer* _layer;
	CCLayer* _layerEpisodes[CAMPAIGN_EPISODE_COUNT];
	CCNode*_actsViewBg;

	CCSprite* _tabButtons[CAMPAIGN_EPISODE_COUNT];

	vector<CCMenuItemSprite*> _arrSprites[CAMPAIGN_EPISODE_COUNT];

	CCLabelTTF* _labelMoney;

	int _touchedTabButtonIndex;
	int _selectedTabIndex;
	int _selectedChapterIndex;

	CCPoint _touchStartPos;

	CampaignSceneTouchPlace  _touchPlace;

	char buf[200];

	vector<string> _friends;
};
